import { } from '@nestjs/typeorm'
import { IsNotEmpty, IsString, IsEmail, IsOptional, ValidateIf, MinLength, MaxLength, IsMobilePhone, IsEnum, IsNumber, IsDate } from 'class-validator'

export class UpdateUserDto {
    @IsOptional()
    @ValidateIf(o => o.name != '')
    @IsString({
        always: true
    })
    @MinLength(3, {
        message: '用户名长度不能少于3位'
    })
    @MaxLength(8, {
        message: '用户名长度不能少于3位'
    })
    name?: string

    @IsOptional()
    @ValidateIf(o => o.phone != '')
    @IsMobilePhone(null, null, {
        message: '手机号格式不正确'
    })
    phone?: string

    @IsOptional()
    @ValidateIf(o => o.age != '')
    @IsEnum([-1, 0, 1])
    sex?: number

    @IsOptional()
    @ValidateIf(o => o.age != '')
    @IsNumber({
        allowInfinity: false,
        allowNaN: false,
    }, {
        message: '年龄格式不正确'
    })
    age?: number

    @IsOptional()
    @ValidateIf(o => o.birthday != '')
    @IsDate({
        message: '生日不能为空'
    })
    birthday?: string

    @IsOptional()
    @ValidateIf(o => o.avatar != '')
    avatar?: string

    @IsOptional()
    @ValidateIf(o => o.address != '')
    address?: string

    @IsOptional()
    @ValidateIf(o => o.password != '')
    @MinLength(8, {
        message: '密码长度不能少于8位'
    })
    @MaxLength(16, {
        message: '密码长度不能超过16位'
    })
    password?: string
}